<template>
  <div class="matrix-view-side">
    <el-row type="flex">
      <el-col :span="12">
        <el-row type="flex" align="middle">
          <div class="icon-rounded">
            <i class="el-icon-star-on"></i>
          </div>
          <div>
            <div class="item-label">收藏</div>
            <div class="item-value">{{ info.collectNum || 0 }}</div>
          </div>
        </el-row>
      </el-col>
      <el-col :span="12">
        <el-row type="flex" align="middle">
          <div class="icon-rounded">
            <i class="el-icon-alarm-clock"></i>
          </div>
          <div>
            <div class="item-label">发布日期</div>
            <div class="item-value">{{ info.publishDate || '--' }}</div>
          </div>
        </el-row>
      </el-col>
    </el-row>
    <el-descriptions title="" :column="2" :colon="false" class="mt-9">
      <el-descriptions-item label="责任人">
        <span class="item-value">{{ matrix.reviser || '--' }}</span>
      </el-descriptions-item>
      <el-descriptions-item label="分类">
        <span class="item-value">{{ matrix.indexType || '--' }}</span>
      </el-descriptions-item>
    </el-descriptions>
    <div class="mt-9">
      <div class="item-label">标签</div>
      <div class="tags mt-3">
        <template v-if="labels.length > 0">
          <div v-for="(item, i) in labels" :key="i" class="tag">
            <svg-icon icon-class="wave-square-rounded" />
            <span>{{ item }}</span>
          </div>
        </template>
      </div>
    </div>
    <div class="divider mt-9"></div>
    <!-- 相关指标 -->
    <div v-if="(info.matrixRelationList || []).length > 0" class="mt-9">
      <div class="item-label">相关指标</div>
      <div class="tags mt-3">
        <div v-for="(item, i) in info.matrixRelationList" :key="i" class="tag">
          <svg-icon icon-class="wave-square-rounded" />
          <span>{{ item }}</span>
        </div>
      </div>
    </div>
    <!-- 关联目标 -->
    <div v-if="(info.matrixTargetList || []).length > 0" class="mt-9">
      <div class="item-label">关联目标</div>
      <div v-for="(item, i) in info.matrixTargetList || []" :key="i" class="mt-4 ralated-aim">
        <el-row type="flex" align="middle">
          <div class="dot"></div>
          <span class="ml-3">{{ item.name }}</span>
        </el-row>
        <el-row type="flex" align="middle">
          <span class="mr-2">{{ item.percent }}%</span>
          <el-progress
            type="circle"
            :percentage="item.percent"
            :width="20"
            :stroke-width="3"
            :show-text="false"
          ></el-progress>
        </el-row>
      </div>
    </div>
  </div>
</template>
<script>
import request from '@/utils/request'
import moment from 'moment'

export default {
  props: {
    matrix: { type: Object, default: () => ({}) },
  },
  data() {
    return {
      info: {},
    }
  },
  computed: {
    labels() {
      return this.matrix.indexLabel ? this.matrix.indexLabel.split(',') : []
    },
  },
  created() {
    this.loadData()
  },
  methods: {
    async loadData() {
      try {
        const { success, data } = await request({
          url: '/jtx/index/center/relation',
          method: 'post',
          data: {
            id: this.$route.params.id,
          },
        })
        if (success) {
          data.matrixTargetList = (data.matrixTargetList || []).map((item) => {
            const ret = item

            if (item.targetValue && item.currentValue !== undefined) {
              ret.percent = ((item.currentValue / item.targetValue) * 100).toFixed(2)
            }

            return ret
          })
          // 格式化日期
          data.publishDate = data.publishTime ? moment(data.publishTime).format('YYYY-MM-DD') : '--'

          this.info = data
        }
      } catch (error) {
        console.log('loadData error=', error)
      }
    },
  },
}
</script>
<style lang="scss" scoped>
.matrix-view-side {
  padding: 24px;

  .divider {
    height: 0;
    width: 100%;
    border-bottom: 1px dashed #dadada;
  }

  .item-label {
    color: #8c8c8c;
    font-size: 14px;
  }
  .item-value {
    color: #262626;
    font-weight: 600;
  }

  .icon-rounded {
    width: 48px;
    height: 48px;
    margin-right: 12px;
    line-height: 48px;
    text-align: center;
    border-radius: 8px;
    background-color: #e6f2fe;
    i {
      display: inline-block;
      width: 24px;
      height: 24px;
      line-height: 24px;
      border-radius: 12px;
      background-color: #30d987;
      color: #fff;

      &.el-icon-alarm-clock {
        background: #0073e5;
      }
    }
  }

  .tags {
    display: flex;
    flex-wrap: wrap;
    .tag {
      display: flex;
      align-items: center;
      height: 32px;
      margin-right: 12px;
      margin-bottom: 4px;
      border-radius: 8px;
      border: 1px solid rgba(0, 0, 0, 0.08);
      padding: 0 12px;
      ::v-deep .svg-icon {
        font-size: 20px;
        margin-right: 8px;
        border: 1px dashed rgba(0, 0, 0, 0.08);
      }
    }
  }

  .ralated-aim {
    height: 40px;
    padding: 0 16px;
    background: #fafafa;
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;

    .dot {
      width: 12px;
      height: 12px;
      border-radius: 6px;
      background-color: var(--primary-color);
    }

    span:first-child {
      color: var(--primary-color);
    }
  }
}
</style>
